package com.zshstart.app.func;


import com.zshstart.utils.SplitWordUtil;
import org.apache.flink.table.annotation.DataTypeHint;
import org.apache.flink.table.annotation.FunctionHint;
import org.apache.flink.table.functions.TableFunction;
import org.apache.flink.types.Row;

import java.util.List;

/**
 * Flink Table 自定义UDTF函数
 *
 * @author zshstart
 * @create 2021-10-09 18:28
 */
@FunctionHint(output = @DataTypeHint("ROW<word STRING>"))
public class SplitFunction extends TableFunction<Row> {

    public void eval(String keyWord) {
        List<String> words = SplitWordUtil.splitKeyWord(keyWord);

        //遍历输出每个单词
        for (String word : words) {
            collect(Row.of(word));
        }
    }
}
